package com.easybuy.entity;

import java.util.List;

/**
 * EasybuyProductCategory 实体类
 * 对应数据库表 easybuy.easybuy_product_category
 */
public class EasybuyProductCategory {
    // 主键
    private Integer id;

    // 名称
    private String name;

    // 父级目录id
    private Integer parentId;

    // 级别(1:一级 2：二级 3：三级)
    private Integer type;

    // 图标
    private String iconClass;

    // 子分类列表（非数据库字段）
    private List<EasybuyProductCategory> children;

    // 无参构造函数
    public EasybuyProductCategory() {
    }

    // 带参构造函数
    public EasybuyProductCategory(Integer id, String name, Integer parentId, Integer type, String iconClass) {
        this.id = id;
        this.name = name;
        this.parentId = parentId;
        this.type = type;
        this.iconClass = iconClass;
    }

    // Getter 和 Setter 方法
    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getParentId() {
        return parentId;
    }

    public void setParentId(Integer parentId) {
        this.parentId = parentId;
    }

    public Integer getType() {
        return type;
    }

    public void setType(Integer type) {
        this.type = type;
    }

    public String getIconClass() {
        return iconClass;
    }

    public void setIconClass(String iconClass) {
        this.iconClass = iconClass;
    }

    public List<EasybuyProductCategory> getChildren() {
        return children;
    }

    public void setChildren(List<EasybuyProductCategory> children) {
        this.children = children;
    }

    // 便捷方法：判断是否为一级分类
    public boolean isLevel1() {
        return type != null && type == 1;
    }

    // 便捷方法：判断是否为二级分类
    public boolean isLevel2() {
        return type != null && type == 2;
    }

    // 便捷方法：判断是否为三级分类
    public boolean isLevel3() {
        return type != null && type == 3;
    }

    // 便捷方法：判断是否为根分类（一级分类的parentId通常为0或特定值）
    public boolean isRootCategory() {
        return isLevel1() && (parentId == null || parentId == 0);
    }

    // 便捷方法：获取级别描述
    public String getTypeDescription() {
        if (type == null) return "未知级别";
        switch (type) {
            case 1: return "一级分类";
            case 2: return "二级分类";
            case 3: return "三级分类";
            default: return "未知级别";
        }
    }

    // 便捷方法：检查是否有子分类
    public boolean hasChildren() {
        return children != null && !children.isEmpty();
    }

    @Override
    public String toString() {
        return "EasybuyProductCategory{" +
                "id=" + id +
                ", name='" + name + '\'' +
                ", parentId=" + parentId +
                ", type=" + type +
                ", iconClass='" + iconClass + '\'' +
                ", childrenCount=" + (children != null ? children.size() : 0) +
                '}';
    }
}